package com.bjfu.gmms.servlet;

import com.bjfu.gmms.MyBatisUtil;
import com.bjfu.gmms.mapper.ApplicationPreferenceMapper;
import com.bjfu.gmms.mapper.MentorMapper;
import com.bjfu.gmms.model.ApplicationPreference;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/volunteerSubmit")
public class VolunteerSubmitServlet extends HttpServlet {
    private ApplicationPreferenceMapper applicationPreferenceMapper;

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int studentId = Integer.parseInt(request.getParameter("studentId"));
        SqlSession sqlSession = MyBatisUtil.getSqlSession("development");
        applicationPreferenceMapper = sqlSession.getMapper(ApplicationPreferenceMapper.class);
        String researchId = request.getParameter("researchId");


            // 插入志愿信息
            applicationPreferenceMapper.insertApplicationPreference(new ApplicationPreference(studentId, Integer.parseInt(request.getParameter("mentorId1")), researchId, 1));
            applicationPreferenceMapper.insertApplicationPreference(new ApplicationPreference(studentId, Integer.parseInt(request.getParameter("mentorId2")), researchId, 2));
            applicationPreferenceMapper.insertApplicationPreference(new ApplicationPreference(studentId, Integer.parseInt(request.getParameter("mentorId3")), researchId, 3));
        sqlSession.commit();
        sqlSession.commit();
        sqlSession.commit();

            /*response.sendRedirect("businessTwo.jsp");*/
        response.sendRedirect("studentDashboard.jsp");


    }
}
